﻿''' <summary>
''' Note: Must be sure to use ReportViewer 2005 (DLL Version 8) in order to access ACP's SQL Server Reporting Services 2005
''' This control is available for download, and should be installed in the GAC, however when done on development machine in 2011
''' there was a problem; although it appeared to be in GAC it was not shown in .NET assemblies dialog so the control could be added.
''' Had to browse to folder containing DLL and manually add it: Windows\assemblies\gac\msil\....
''' </summary>
Public Class frmReporting

    Private _ServerURL As String, _UserName As String, _Password As String, _ReportPath As String, _ReportName As String, _Timeout As Integer

    ''' <summary>
    ''' Instantiate form
    ''' </summary>
    ''' <param name="ServerURL">URL of report server (e.g., http://hidromet/ReportServer) </param>
    ''' <param name="UserName">User name (blank for Windows authentication)</param>
    ''' <param name="Password">Password</param>
    ''' <param name="ReportPath">Path to report location (e.g., /Produccion/BDH/Informes de Calidad de Agua/)</param>
    ''' <param name="ReportName">Name of report on server (e.g., BDHC0001)</param>
    ''' <remarks></remarks>
    Public Sub New(ByVal ServerURL As String, ByVal UserName As String, ByVal Password As String, ByVal ReportPath As String, ByVal Timeout As Integer, ByVal ReportName As String)
        InitializeComponent()

        _ServerURL = ServerURL
        _UserName = UserName
        _Password = Password
        _ReportPath = ReportPath
        _Timeout = Timeout
        'report path must begin and end with slashes
        If Not _ReportPath.StartsWith("/") Then _ReportPath = "/" & _ReportPath
        If Not _ReportPath.EndsWith("/") Then _ReportPath &= "/"
        _ReportName = ReportName
    End Sub

    Private Sub frmReporting_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        SaveWindowPos("WRDB", Me)
    End Sub

    Private Sub frmReporting_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            GetWindowPos("WRDB", Me)
            'With ReportViewer1
            '    .ServerReport.Timeout = _Timeout * 1000
            '    .ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote
            '    .ServerReport.ReportServerUrl = New System.Uri(_ServerURL)
            '    If _UserName <> "" Then
            '        .ServerReport.ReportServerCredentials.NetworkCredentials = New System.Net.NetworkCredential(_UserName, _Password)
            '    Else
            '        .ServerReport.ReportServerCredentials.NetworkCredentials = System.Net.CredentialCache.DefaultCredentials
            '    End If
            '    .ServerReport.ReportPath = _ReportPath & _ReportName
            '    .RefreshReport()
            'End With
        Catch ex As Exception
            ErrorMsg(, ex)
        End Try
    End Sub

    Private Sub frmReporting_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
        With ReportViewer1
            .ServerReport.Timeout = _Timeout * 1000
            .ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote
            .ServerReport.ReportServerUrl = New System.Uri(_ServerURL, System.UriKind.Absolute)
            If _UserName <> "" Then
                .ServerReport.ReportServerCredentials.NetworkCredentials = New System.Net.NetworkCredential(_UserName, _Password)
            Else
                .ServerReport.ReportServerCredentials.NetworkCredentials = System.Net.CredentialCache.DefaultCredentials
            End If
            '.ServerReport.ReportServerCredentials.NetworkCredentials = New System.Net.NetworkCredential("lcw", "Waterres@2", "http://winweb2008")
            .ServerReport.ReportPath = _ReportPath & _ReportName
            .RefreshReport()
        End With
    End Sub
End Class